
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Pig;
import cn.edu.scau.cmi.hombio.domain.Pigsty;
import cn.edu.scau.cmi.hombio.domain.Task;
import cn.edu.scau.cmi.hombio.domain.Transfer;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class TransferServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected TransferService service;

	/**
	 * Instantiates a new TransferServiceTest.
	 *
	 */
	public TransferServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Save an existing Transfer entity
	* 
	 */
	@Test
	public void saveTransfer() {
		// TODO: JUnit - Populate test inputs for operation: saveTransfer 
		Transfer transfer = new cn.edu.scau.cmi.hombio.domain.Transfer();
		service.saveTransfer(transfer);
	}

	/**
	 * Operation Unit Test
	* Save an existing Pig entity
	* 
	 */
	@Test
	public void saveTransferPig() {
		// TODO: JUnit - Populate test inputs for operation: saveTransferPig 
		Integer id = 0;
		Pig related_pig = new cn.edu.scau.cmi.hombio.domain.Pig();
		Transfer response = null;
		response = service.saveTransferPig(id, related_pig);
		// TODO: JUnit - Add assertions to test outputs of operation: saveTransferPig
	}

	/**
	 * Operation Unit Test
	* Save an existing Task entity
	* 
	 */
	@Test
	public void saveTransferTask() {
		// TODO: JUnit - Populate test inputs for operation: saveTransferTask 
		Integer id_1 = 0;
		Task related_task = new cn.edu.scau.cmi.hombio.domain.Task();
		Transfer response = null;
		response = service.saveTransferTask(id_1, related_task);
		// TODO: JUnit - Add assertions to test outputs of operation: saveTransferTask
	}

	/**
	 * Operation Unit Test
	* Delete an existing Task entity
	* 
	 */
	@Test
	public void deleteTransferTask() {
		// TODO: JUnit - Populate test inputs for operation: deleteTransferTask 
		Integer transfer_id = 0;
		Integer related_task_id = 0;
		Transfer response = null;
		response = service.deleteTransferTask(transfer_id, related_task_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteTransferTask
	}

	/**
	 * Operation Unit Test
	* Delete an existing Transfer entity
	* 
	 */
	@Test
	public void deleteTransfer() {
		// TODO: JUnit - Populate test inputs for operation: deleteTransfer 
		Transfer transfer_1 = new cn.edu.scau.cmi.hombio.domain.Transfer();
		service.deleteTransfer(transfer_1);
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findTransferByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findTransferByPrimaryKey 
		Integer id_2 = 0;
		Transfer response = null;
		response = service.findTransferByPrimaryKey(id_2);
		// TODO: JUnit - Add assertions to test outputs of operation: findTransferByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Delete an existing Pigsty entity
	* 
	 */
	@Test
	public void deleteTransferPigsty() {
		// TODO: JUnit - Populate test inputs for operation: deleteTransferPigsty 
		Integer transfer_id_1 = 0;
		Integer related_pigsty_id = 0;
		Transfer response = null;
		response = service.deleteTransferPigsty(transfer_id_1, related_pigsty_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteTransferPigsty
	}

	/**
	 * Operation Unit Test
	* Return all Transfer entity
	* 
	 */
	@Test
	public void findAllTransfers() {
		// TODO: JUnit - Populate test inputs for operation: findAllTransfers 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Transfer> response = null;
		response = service.findAllTransfers(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllTransfers
	}

	/**
	 * Operation Unit Test
	* Save an existing Pigsty entity
	* 
	 */
	@Test
	public void saveTransferPigsty() {
		// TODO: JUnit - Populate test inputs for operation: saveTransferPigsty 
		Integer id_3 = 0;
		Pigsty related_pigsty = new cn.edu.scau.cmi.hombio.domain.Pigsty();
		Transfer response = null;
		response = service.saveTransferPigsty(id_3, related_pigsty);
		// TODO: JUnit - Add assertions to test outputs of operation: saveTransferPigsty
	}

	/**
	 * Operation Unit Test
	* Delete an existing Pig entity
	* 
	 */
	@Test
	public void deleteTransferPig() {
		// TODO: JUnit - Populate test inputs for operation: deleteTransferPig 
		Integer transfer_id_2 = 0;
		Integer related_pig_id = 0;
		Transfer response = null;
		response = service.deleteTransferPig(transfer_id_2, related_pig_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteTransferPig
	}

	/**
	 * Operation Unit Test
	* Load an existing Transfer entity
	* 
	 */
	@Test
	public void loadTransfers() {
		Set<Transfer> response = null;
		response = service.loadTransfers();
		// TODO: JUnit - Add assertions to test outputs of operation: loadTransfers
	}

	/**
	 * Operation Unit Test
	* Return a count of all Transfer entity
	* 
	 */
	@Test
	public void countTransfers() {
		Integer response = null;
		response = service.countTransfers();
		// TODO: JUnit - Add assertions to test outputs of operation: countTransfers
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
